package com.doubao.doubao_admin;

import com.doubao.doubao_admin.jwt.JwtAuthenticationFiler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

@MapperScan("com.doubao.doubao_admin.mapper")
@SpringBootApplication
public class DouboApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){

        return builder.sources(DouboApplication.class);
    }

    @Bean//在spring容器中自动被初始化,最新版此处不需要@Bean注解
    public FilterRegistrationBean jwtFilter(){
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        JwtAuthenticationFiler filer = new JwtAuthenticationFiler();
        registrationBean.addUrlPatterns("/*");
        registrationBean.setFilter(filer);
        return registrationBean;
    }

    public static void main(String[] args) {
        SpringApplication.run(DouboApplication.class, args);
    }

}
